<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>从一个数组中选择元素 - slice()</title>
</head>

<body>
    <p id="demo">点击按钮截取数组下标 1 到 2 的元素。</p>
    <button onclick="myFunction()">点我</button>
    <script>
        function myFunction() {
            var fruits = ["P", "A", "Q", "B"];
            var citrus = fruits.slice(1, 3);
            var x = document.getElementById("demo");
            x.innerHTML = citrus;
        }
    </script>
</body>

</html>